const { app, session } = require('electron')

app.whenReady().then(() => {
  createSession()
  // sessionStorage()
})

function createSession() {
  console.log(session)
  const s = session.defaultSession
  const s1 = session.fromPartition('hello', { cache: false })
  const s2 = session.fromPartition('world')
  const s3 = session.fromPartition('hello', { cache: true })
  console.log(s1 === s2)
  console.log(s1 === s3)
  console.log(s === s1)
  const ses = session.fromPartition('persist:name')
  console.log(ses.getUserAgent())
}

async function sessionStorage() {
  const newSession = session.fromPartition('new', { cache: false })
  console.log(newSession.getStoragePath())
  const cacheSession = session.fromPartition('persist:new', { cache: true })
  console.log('getCacheSize', await cacheSession.getCacheSize())
  await cacheSession.clearCache()
  console.log('getCacheSize', await cacheSession.getCacheSize())
  console.log(cacheSession.getStoragePath())
  setTimeout(() => cacheSession.flushStorageData(), 3000)
  setTimeout(async () => console.log('getCacheSize', await cacheSession.getCacheSize()), 5000)
}
